package com.cl.pile.rule.func;

import com.alibaba.fastjson.JSONObject;
import com.cl.pile.rule.process.RuleMatcher;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author chenyitao
 * @date 2021/6/8
 */
public class SumFunc extends NumBaseFunc {

    @Override
    public Object func(List<Object> data, String rootVar, Object root, JSONObject ruleJson, RuleMatcher ruleMatcher) {
        BigDecimal sum = numFuncCb(new BigDecimal(0), data, ruleJson, ruleMatcher, rootVar, root, BigDecimal::add);
        return sum.toString();
    }

    @Override
    public String funcName() {
        return "求和";
    }
}
